<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<head>
    <t:base type="jquery,easyui,tools,echarts,map.china"></t:base>
    <script type="text/javascript" src="plug-in/Highcharts-4.2.4/highcharts.js"></script>
    <style type="text/css">
        .tabs-header {
            background: white;
        }

        a {
            color: Blue;
            text-decoration: underline;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            var flag = false;
            $("#tabs").tabs({
                onSelect: function (title) {
                    if (title == '各机型问题汇总' && !flag) {//只加载一次
                        getEsTableData($("#year_2").val());//默认根据默认年份加载
                        initallEsHighChartsOfPie();
                        initallEsHighChartsOfLine();
                        flag = true;
                    }
                }
            });
            var year1 = $("#year_1").val();
            getTtTableData(year1);
            //initallTTHighChartsOfPillar(year1);
            installTTHcPillarAndEcMap(year1);
            initallTTHighChartsOfLine();
        });

        /**
         * 因为各省问题汇总 堆叠柱状图 & map 所用数据一致，所以一起初始化
         */
        function installTTHcPillarAndEcMap(year, departIds, irExType, ttIds) {
            var pillarData = getTTPillarData(year, departIds, irExType, ttIds);
            initallTTHighChartsOfPillar(pillarData);
            installEcMap(pillarData);
        }

        function installEcMap(pillarData) {
            var option = {
                title: {
                    text: '全国巡检异常记录',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: '{b}<br/>{c}'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: []
                },
                visualMap: {
                    min: 0,
                    max: 100,
                    left: 'left',
                    top: 'bottom',
                    text: ['高', '低'],           // 文本，默认为数值文本
                    calculable: true,
                    inRange: {
                        color: ['rgba(26,184,10,1)', 'rgba(252,165,1,.7)', 'rgba(205,3,3,1)'],
                        symbolSize: 3
                    }
                },
                series: []
            };
            var citys = pillarData[0].citys;
            var pillarDataNew = []
            for (var i in pillarData) {
                //克隆复制复杂结构的数组太繁琐，所以不剔除 0 位置的元素。而采用取出除 0 意外的元素
                if (i == 0) {
                    continue;
                }
                pillarDataNew.push(pillarData[i]);
            }
            var series = [], ttExCountArr = new Array(citys.length);
            var max = 100;
            $.each(pillarDataNew, function (i, item) {
                var seri = {
                    name: '',
                    type: 'map',
                    mapType: 'china',
                    label: {
                        normal: {
                            show: true
                        },
                        emphasis: {
                            show: true
                        }
                    },
                    data: []
                }
                option.legend.data.push(item.name);
                seri.name = item.name;
                var dataArr = [];
                $.each(item.data, function (j, item_j) {
                    var seriData = {};
                    <%--			if(item_j == 0){--%>
                    <%--				return true;//排除0 的数据--%>
                    <%--			}--%>
                    seriData.name = citys[j].replace(/自治区|维吾尔自治区|省|市/, '');
                    seriData.value = item_j;
                    dataArr.push(seriData);
                    ttExCountArr[j] = ttExCountArr[j] == undefined ? 0 + item_j : ttExCountArr[j] + item_j;//保存每个省份的所有异常累加
                })
                seri.data = dataArr;
                series.push(seri);
            });
            for (var i in ttExCountArr) {
                max = max > ttExCountArr[i] ? max : ttExCountArr[i];//取出最大值
            }
            option.visualMap.max = max;
            option.series = series;
            //console.log(series);
            var myChart = echarts.init(document.getElementById('ecChainMapCtn'));
            myChart.setOption(option);
        }

        function getTtTableData(year, departIds, irExType, ttIds) {
            $.ajax({
                url: "zyInspectionReportController.do?getIrTtTableData",
                data: {
                    "year": year,
                    "departIds": departIds,
                    "irExType": irExType,
                    "ttIds": ttIds
                },
                cache: false,
                async: false,//必须是同步进行，为了获取 初始化 highcharts 数据
                dataType: 'json',
                type: 'POST',
                success: function (data) {
                    if (data.success) {
                        //clearTTPillarData();//每次初始化表格时清空临时储存的highchart数据
                        clearTTLineCharData();
                        /*----------------表格-------------------*/
                        var obj = data.obj;
                        var html = "", rowTotal = 0;
                        var lineCharArr = [];
                        $(obj).each(function (r, item_r) {
                            lineCharArr = [];
                            html += "<tr>";
                            html += "<td class='r" + (r + 1) + "_c0'>" + item_r.territoryname + "</td>";
                            var numInMonth = 0;
                            for (var c = 1; c < 13; c++) {
                                numInMonth = item_r[c] != undefined ? parseInt(item_r[c]) : 0;
                                rowTotal += numInMonth;
                                html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + c + ',\'\',\'' + item_r.ttId + '\',\'\',\'\')"><span class="r' + (r + 1) + '_c' + c + '">' + numInMonth + '</span></a></td>' : '<td><span class="r' + (r + 1) + '_c' + c + '">' + numInMonth + '</td>';
                                lineCharArr.push(numInMonth);
                            }
                            html += "<td class='r" + (r + 1) + "_c13'>" + rowTotal + "</td>";
                            html += "</tr>";
                            //setTTPillarData(item_r.territoryname,rowTotal);改为单独post查询
                            setTTLineCharData(item_r.territoryname, lineCharArr);
                            rowTotal = 0;
                        });
                        if ($("#ttTable tr").length > 1) {
                            $("#ttTable tr:gt(0)").remove();
                        }
                        $("#ttTable").append(html);
                        /*------------------end 表格------------------*/
                    } else {
                        tip(data.msg);
                    }
                }
            });
        }

        function getTTPillarData(year, departIds, irExType, ttIds) {
            var chartData;
            $.ajax({
                url: "zyInspectionReportController.do?queryEachCityPillarData",
                data: {
                    "year": year,
                    "departIds": departIds,
                    "irExType": irExType,
                    "ttIds": ttIds
                },
                cache: false,
                async: false,//必须是同步进行，为了获取 初始化 highcharts 数据
                dataType: 'json',
                type: 'POST',
                success: function (data) {
                    chartData = data;
                }
            });
            return chartData;
        }

        var ttLineCharData = [];

        function clearTTLineCharData() {
            ttLineCharData = [];
        }

        function setTTLineCharData(name, dataArr) {
            var dt = {};
            dt.name = name;
            dt.data = dataArr;
            ttLineCharData.push(dt);
        }

        function getTTLineCharData() {
            var index = $("#tabs").tabs('getTabIndex', $('#tabs').tabs('getSelected')) + 1;
            var ttVal = $("#tt_" + index).val();
            if (ttVal !== null && ttVal !== '' && ttVal !== undefined) {
                return ttLineCharData;
            } else {
                /**排序后 取前十*/
                ttLineCharData.sort(function (a, b) {
                    var aCount = 0;
                    for (var i in a.data) {
                        aCount += a.data[i];
                    }
                    var bCount = 0;
                    for (var i in b.data) {
                        bCount += b.data[i];
                    }
                    return bCount - aCount;
                });
                var top10 = [];
                for (var i = 0; i < 10; i++) {
                    top10.push(ttLineCharData[i]);
                }
                /**排序后 取前十 end*/
                return top10;
            }
        }

        function initallTTHighChartsOfPillar(pillarData) {
            var categories = pillarData[0].citys;
            var series = []
            for (var i in pillarData) {
                //克隆复制复杂结构的数组太繁琐，所以不剔除 0 位置的元素。而采用取出除 0 意外的元素
                if (i == 0) {
                    continue;
                }
                series.push(pillarData[i]);
            }
            /*-----------------柱状图-------------------*/
            Highcharts.chart("highchartContainerOfTTPillar", {
                credits: {//去水印
                    text: '',
                    href: ''
                },
                chart: {
                    type: 'column'
                },
                title: {
                    text: '全国各省巡检问题'
                },
                xAxis: {
                    categories: categories
                },
                yAxis: {
                    min: 0,
                    title: {
                        text: '巡检问题累计数量'
                    }
                },
                tooltip: {
                    shared: true
                },
                plotOptions: {
                    column: {
                        stacking: 'normal',
                        borderWidth: 0
                    }
                },
                series: series
            });
            /*-----------------end 柱状图------------------*/
        }

        function initallTTHighChartsOfLine() {
            /*-------------------- 折线图 -------------------------*/
            $("#highchartContainerOfTTLine").highcharts({
                credits: {//去水印
                    text: '',
                    href: ''
                },
                title: {
                    text: '全国各省各月巡检问题',
                    x: -20 //center
                },
                xAxis: {
                    categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                },
                yAxis: {
                    title: '',
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    borderWidth: 0
                },
                series: getTTLineCharData()
            });
        }

        /**------------------------按照机型汇总-----------------------*/
        function getEsTableData(year, departId, esTypes) {
            $.ajax({
                url: "zyInspectionReportController.do?getIpProblemReportData",
                data: {
                    "year": year,
                    "departIds": departId,
                    "esTypes": esTypes
                },
                cache: false,
                async: false,//必须是同步进行，为了获取 初始化 highcharts 数据
                dataType: 'json',
                type: 'POST',
                success: function (data) {
                    if (data.success) {
                        clearEsPieData();//每次初始化表格时清空临时储存的highchart数据
                        clearEsLineCharData();
                        var monthTotalMap = data.attributes;//每个月巡检计划总数 (key 月份，value 月份对应巡检计划数量)
                        /*----------------表格-------------------*/
                        var obj = data.obj;
                        var numInMonth, monthArr = [];
                        var html = "";
                        html += "<tr><td>零地电压异常</td>";
                        var rowTotal = 0;
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.zeroGroundVoltageExs[i].total != 0 ? obj.zeroGroundVoltageExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',1,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r1_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r1_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                            //monthArr.push(parseInt(numInMonth));
                        }
                        setEsLineCharData("零地电压异常", monthArr);
                        setEsPieData("零地电压异常", rowTotal);
                        html += rowTotal != 0 ? '<td id="zeroGroundVoltage"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',1,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r1_12">' + rowTotal + '</span></a></td></tr>' : '<td id="zeroGroundVoltage"><span class="r1_12">0</span></td>';

                        rowTotal = 0;
                        numInMonth = 0;
                        monthArr = [];
                        html += "<tr><td>湿度过大</td>";
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.humidityExs[i].total != 0 ? obj.humidityExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',2,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r2_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r2_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                        }
                        setEsLineCharData("湿度过大", monthArr);
                        setEsPieData("湿度过大", rowTotal);
                        html += rowTotal != 0 ? '<td id="humidity"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',2,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r2_12">' + rowTotal + '</span></a></td></tr>' : '<td id="humidity"><span class="r2_12">0</span></td>';

                        rowTotal = 0;
                        numInMonth = 0;
                        monthArr = [];
                        html += "<tr><td>温度异常</td>";
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.temperatureExs[i].total != 0 ? obj.temperatureExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',3,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r3_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r3_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                        }
                        setEsLineCharData("温度异常", monthArr);
                        setEsPieData("温度异常", rowTotal);
                        html += rowTotal != 0 ? '<td id="temperature"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',3,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r3_12">' + rowTotal + '</span></a></td></tr>' : '<td id="temperature"><span class="r3_12">0</span></td>';

                        rowTotal = 0;
                        numInMonth = 0;
                        monthArr = [];
                        html += "<tr><td>冷却液压力异常</td>";
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.coolantPressureExs[i].total != 0 ? obj.coolantPressureExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',4,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r4_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r4_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                        }
                        setEsLineCharData("冷却液压力异常", monthArr);
                        setEsPieData("冷却液压力异常", rowTotal);
                        html += rowTotal != 0 ? '<td id="coolantPressure"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',4,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r4_12">' + rowTotal + '</span></a></td></tr>' : '<td id="coolantPressure"><span class="r4_12">0</span></td>';

                        rowTotal = 0;
                        numInMonth = 0;
                        monthArr = [];
                        html += "<tr><td>冷却液面高度异常</td>";
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.coolantHeightExs[i].total != 0 ? obj.coolantHeightExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',5,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r5_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r5_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                        }
                        setEsLineCharData("冷却液面高度异常", monthArr);
                        setEsPieData("冷却液面高度异常", rowTotal);
                        html += rowTotal != 0 ? '<td id="coolantHeight"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',5,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r5_12">' + rowTotal + '</span></a></td></tr>' : '<td id="coolantHeight"><span class="r5_12">0</span></td>';

                        rowTotal = 0;
                        numInMonth = 0;
                        monthArr = [];
                        html += "<tr><td>亮度低</td>";
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.brightnessExs[i].total != 0 ? obj.brightnessExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',6,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r6_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r6_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                        }
                        setEsLineCharData("亮度低", monthArr);
                        setEsPieData("亮度低", rowTotal);
                        html += rowTotal != 0 ? '<td id="brightness"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',6,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r6_12">' + rowTotal + '</span></a></td></tr>' : '<td id="brightness"><span class="r6_12">0</span></td>';

                        rowTotal = 0;
                        numInMonth = 0;
                        monthArr = [];
                        html += "<tr><td>风速异常</td>";
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.windSpeedExs[i].total != 0 ? obj.windSpeedExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',7,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r7_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r7_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                        }
                        setEsLineCharData("风速异常", monthArr);
                        setEsPieData("风速异常", rowTotal);
                        html += rowTotal != 0 ? '<td id="windSpeed"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',7,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r7_12">' + rowTotal + '</span></a></td></tr>' : '<td id="windSpeed"><span class="r7_12">0</span></td>';

                        rowTotal = 0;
                        numInMonth = 0;
                        monthArr = [];
                        html += "<tr><td>参加培训人员不足</td>";
                        for (var i = 0; i < 12; i++) {
                            numInMonth = obj.trainingNumExs[i].total != 0 ? obj.trainingNumExs[i].total : 0;
                            rowTotal += numInMonth;
                            html += numInMonth != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',8,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r8_' + i + '">' + numInMonth + '</span></a></td>' : '<td><span class="r8_' + i + '">0</span></td>';
                            monthArr.push(monthTotalMap[i + 1] == 0 ? 0 : parseInt(numInMonth / monthTotalMap[i + 1] * 100));
                        }
                        setEsLineCharData("参加培训人员不足", monthArr);
                        setEsPieData("参加培训人员不足", rowTotal);
                        html += rowTotal != 0 ? '<td id="trainingNum"><a href="javacript:void(0)" onclick="goViewPlan(' + year + ',\'\',8,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r8_12">' + rowTotal + '</span></a></td></tr>' : '<td id="trainingNum"><span class="r8_12">0</span></td>';

                        //初次加载不需要清除
                        var rowTotalnum = $("#pbTable tr").length;//行数
                        if ($("#pbTable tr").length > 3) {
                            for (var i = rowTotalnum - 3; i >= 1; i--) {
                                $("#pbTable tr:eq(" + i + ")").remove();
                            }
                        }
                        $("#pbTable tr:eq(0)").after(html);

                        /**---特殊添加---**/
                        rowTotal = 0;
                        html = "<tr><td>有问题的巡检台数</td>";//清空html
                        for (var i = 0; i < 12; i++) {//有问题的巡检任务数
                            rowTotal += obj.ipExInMonth[i].total != 0 ? obj.ipExInMonth[i].total : 0;
                            html += obj.ipExInMonth[i].total != 0 ? '<td><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',' + (i + 1) + ',-1,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')"><span class="r9_' + i + '">' + obj.ipExInMonth[i].total + '</span></a></td>' : '<td><span class="r9_' + i + '">0</span></td>';
                        }
                        html += rowTotal != 0 ? '<td id="ipExInMonth"><a href="javascript:void(0)" onclick="goViewPlan(' + year + ',\'\',-1,\'\',\''+obj.departIds+'\',\''+obj.esTypes+'\')" ><span class="r9_12">' + rowTotal + '</span></a></td>' : '<td id="ipExInMonth"><span class="r9_12">0</span></td>';

                        rowTotal = 0;
                        html += "</tr><tr><td>巡检总台数</td>";
                        var inMonth = 0;
                        for (var i = 0; i < 12; i++) {//巡检任务总数
                            inMonth = monthTotalMap[i + 1] == undefined ? 0 : monthTotalMap[i + 1];
                            html += '<td><span class="r10_' + i + '">' + inMonth + '</span></td>';
                            //html += inMonth != 0  ? '<td><a href="javascript:void(0)" onclick="goViewIps('+year+','+(i+1)+')"><span class="r10_'+i+'">'+ inMonth +'</span></a></td>' : '<td><span class="r10_'+i+'">0</span></td>';
                        }
                        html += '<td id="ipsInMonth"><span class="r10_12">' + monthTotalMap.yearTotal + '</span></td>';

                        html += "</tr>";
                        $("#pbTable tr:eq(8)").after(html);//在问题总数后边添加
                        /**---特殊添加--end--**/

                        var rowTotal_index = $("#pbTable tr").length - 2;//问题总数行号
                        var rowpt_index = rowTotal_index + 1;//问题占比行号
                        for (var c = 1; c < 14; c++) {
                            var c_count = 0;//每个月的异常项总数
                            var c_ex_ir_count = monthTotalMap.irExMap[c] == undefined ? 0 : monthTotalMap.irExMap[c];//每个月实际异常的巡检报告数量
                            for (var r = 1; r < 8; r++) {//每个异常项
                                c_count += parseInt($(".r" + r + "_" + (c - 1)).html());
                            }
                            $("#pbTable tr:eq(" + rowTotal_index + ") td:eq(" + c + ")").html(c_count);//问题总数
                            var percentage;
                            if (c <= 12) {
                                //1 至 12 月份列 占比
                                var monthTotal = monthTotalMap[c] == undefined ? 0 : monthTotalMap[c];
                                if (parseInt(monthTotal) == 0) {
                                    percentage = 0;
                                } else {
                                    percentage = c_ex_ir_count / monthTotal * 100;
                                }
                            } else {
                                //总计列 占比
                                percentage = monthTotalMap.irExMap.total / monthTotalMap.yearTotal * 100;
                                percentage = isNaN(percentage) ? 0 : percentage;
                            }
                            $("#pbTable tr:eq(" + rowpt_index + ") td:eq(" + c + ")").html(parseInt(percentage) + "%");//问题占比
                        }
                        /*------------------end 表格------------------*/
                    } else {
                        tip(data.msg);
                    }
                }
            });
        }

        var esPieData = [];

        function setEsPieData(name, y) {
            var data = {};
            data.name = name;
            data.y = y;
            esPieData.push(data);
        }

        function clearEsPieData() {
            esPieData = [];
        }

        function getEsPieDataOfHC() {
            return esPieData;
        }

        var esLineData = [];

        function setEsLineCharData(name, data) {
            var dt = {};
            dt.name = name;
            dt.data = data;
            esLineData.push(dt);
        }

        function clearEsLineCharData() {
            esLineData = [];
        }

        function getEsLineCharData() {
            return esLineData;
        }

        function initallEsHighChartsOfPie() {
            /*-----------------饼图-------------------*/
            $("#highchartContainerOfEsPie").highcharts({
                credits: {//去水印
                    text: '',
                    href: ''
                },
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    x: 10,
                    y: 20,
                    borderWidth: 0,
                    labelFormatter: function () {
                        return this.name + '<br/>&nbsp';
                    },
                    useHTML: true
                },
                title: {
                    text: '巡检出现问题',
                    style: {
                        'font-family': ['Arial Negreta', 'Arial'],
                        'font-weight': '700',
                        'font-style': 'normal',
                        'font-size': '18px'
                    },
                    x: -100
                },
                tooltip: {
                    pointFormat: '数量：<b>{point.y}</b><br/>占比: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: false
                        },
                        size: 200,
                        dataLabels: {
                            enabled: true,
                            formatter: function () {
                                if (this.percentage > 0) return this.point.name + '：' + this.point.y + '<br/>占比:' + Highcharts.numberFormat(this.point.percentage, 1) + '%';
                            },
                            color: 'black',
                            style: {
                                font: '13px Trebuchet MS, Verdana, sans-serif'
                            }
                        },
                        showInLegend: true
                    }
                },
                series: [{
                    type: 'pie',
                    name: '巡检问题',
                    data: getEsPieDataOfHC()
                }]
            });
            /*-----------------end 饼图------------------*/
        }

        function initallEsHighChartsOfLine() {
            $("#highchartContainerOfEsLine").highcharts({
                credits: {//去水印
                    text: '',
                    href: ''
                },
                title: {
                    text: '各月问题数量',
                    x: -20 //center
                },
                xAxis: {
                    categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                },
                yAxis: {
                    title: '',
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }],
                    labels: {
                        formatter: function () {
                            return this.value + ' %';
                        }
                    }
                },
                tooltip: {
                    headerFormat: '<b>{series.name}</b><br/>',
                    pointFormat: '{point.x} 月: {point.y} %'
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    borderWidth: 0
                },
                series: getEsLineCharData()
            });
        }

        function setHighChartData(tab) {
            if (tab == 1) {
                var chartLine = $("#highchartContainerOfTTLine").highcharts();
                var ttLineDataArr = getTTLineCharData();
                //因为这里涉及到series数量的变换，所以需要清空所有series再重新添加
                for (var i = chartLine.series.length - 1; i >= 0; i--) {
                    chartLine.series[i].remove(false);
                }
                for (var i = 0; i < ttLineDataArr.length; i++) {
                    chartLine.addSeries(ttLineDataArr[i], false, false);
                }
                chartLine.redraw();
            } else if (tab == 2) {
                var chartPie = $("#highchartContainerOfEsPie").highcharts();
                chartPie.series[0].setData(getEsPieDataOfHC());
                var chartLine = $("#highchartContainerOfEsLine").highcharts();
                var esLineDataArr = getEsLineCharData();
                for (var i = 0; i < esLineDataArr.length; i++) {
                    chartLine.series[i].setData(esLineDataArr[i].data);
                }
            }

        }

        /**
         * year 年份
         * month 月份
         * exType 异常类型
         * ttId 省份Id
         */
        function goViewPlan(year, month, exType, ttId,departIds,esItems) {
            var url = "zyInspectionPlanController.do?ipListOfIpProblemAnalysisReport&year=" + year + "&month=" + month + "&exType=" + exType + "&ttId=" + ttId +"&departIds=" + departIds+"&esTypes=" + esItems;
            addOneTab("巡检计划", url);
        }

        /**
         * 根据巡检计划年度和月份直接查看巡检计划
         */
        function goViewIps(ipEndTimeYear, ipEndTimeMonth) {
            var url = "zyInspectionPlanController.do?ipListOfIpProblemAnalysisReport&ipEndTimeYear=" + ipEndTimeYear + "&ipEndTimeMonth=" + ipEndTimeMonth;
            addOneTab("巡检计划", url);
        }

        function searchReport(tab) {
            var year = $("#year_" + tab).val();
            var departId = $("#departId_" + tab).val();
            if (tab == 1) {
                var irExType = $("#irExType").val();
                var ttIds = $("#tt_" + tab).val();
                getTtTableData(year, departId, irExType, ttIds);
                installTTHcPillarAndEcMap(year, departId, irExType, ttIds);
            } else if (tab == 2) {
                var esTypes = [];
                $("input[name='esTypeId']").each(function () {
                    esTypes.push($(this).val());
                });
                getEsTableData(year, departId, esTypes.join(","));
            }
            setHighChartData(tab);
        }

        function exportReport(tab) {
            var tableData = [];
            if (tab == 1) {
                var thOrTd = "th";
                $("#ttTable tr").each(function (r, item_r) {
                    var rowData = [];
                    if (r > 0) {
                        thOrTd = "td";
                    }
                    $(item_r).find(thOrTd).each(function (c, item_c) {
                        rowData.push($(".r" + r + "_c" + c).html());
                    });
                    tableData.push(rowData.join(","));
                });
            } else if (tab == 2) {
                $("#pbTable tr").each(function (r, item_r) {
                    var rowData = [];
                    if (r == 0) {
                        $(this).find("th").each(function (c, item_c) {
                            rowData.push($(item_c).html());
                        });
                    } else {
                        $(this).find("td").each(function (c, item_c) {
                            if (c == 0 || r == 11 || r == 12) {
                                rowData.push($(item_c).html());
                            } else {
                                //console.log($(".r" + r + "_" + (c-1)).html());
                                rowData.push($(".r" + r + "_" + (c - 1)).html());
                            }
                        });
                    }
                    tableData.push(rowData.join(","));
                });
            }
            var url = "zyInspectionReportController.do?exportIrReport";
            myDownload(url, "tableData=" + tableData.join(";") + "&fileName='巡检问题分析报表.xlsx'");

        }
    </script>
</head>
<body style="padding: 0px;margin: 0px auto;overflow:scroll;">
<div class="easyui-tabs" id="tabs" style="overflow:scroll;">
    <div title="各省问题汇总" style="overflow: hidden;">
        <div class="pad_l_10">
            <table width="100%">
                <tr>
                    <td style="width: 150px;">
                        <label class="report_label">巡检年度</label>
                        <select id="year_1" style="width:85px;">
                            <c:forEach items="${years }" var="item">
                                <option value="${item }">${item }&nbsp;年</option>
                            </c:forEach>
                        </select>
                    </td>
                    <td>
                        <label class="report_label">机构</label>
                        <input id="departId_1" type="hidden">
                        <input id="departname_1" readonly="readonly" style="width: 150px;"/>
                        <t:choose hiddenName="departId_1" hiddenid="id" inputTextname="departname_1"
                                  textname="shortname"
                                  title="机构列表" url="zyInspectionReportController.do?goChooseOrgsForIrReport"
                                  name="orgList" width="660px" height="550px"
                                  icon="icon-search" isclear="true"></t:choose>
                    </td>
                    <td>
                        <label class="report_label">省</label>
                        <input id="tt_1" type="hidden">
                        <input id="ttName_1" readonly="readonly" style="width: 150px;"/>
                        <t:choose hiddenName="tt_1" hiddenid="id" inputTextname="ttName_1" textname="territoryname"
                                  title="省份列表" url="zyInspectionReportController.do?goChooseTTForIrReport" name="ttList"
                                  width="500px" height="600px"
                                  icon="icon-search" isclear="true"></t:choose>
                    </td>
                    <td>
                        <label class="report_label">巡检报告异常类型</label>
                        <t:dictSelect field="" id="irExType" typeGroupCode="<%=StaticValue.DIC_IR_EX_TYPE %>"
                                      type="select"/>
                    </td>
                    <td style="width: 40px;">
                        <a href="javascript:void(0);" style="width: 90%;" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                           onclick="searchReport(1)">查询</a>
                    </td>
                </tr>
            </table>
            <div style="text-align:right; padding-right:10px;">
                <a href="javascript:void(0);" class="easyui-linkbutton"
                   data-options="iconCls:'icon-putout',plain:'true'" onclick="exportReport(1)">导出报告</a>
            </div>
            <div id="ecChainMapCtn" style="width: 47%;height:600px;display: inline-block;"></div>
            <div id="highchartContainerOfTTLine" style="width: 46%;height:600px;display: inline-block;"></div>
            <br/>
            <div id="highchartContainerOfTTPillar" style="width: 97%;height:600px;"></div>
            <hr/>
            <table id="ttTable" class="report_table">
                <tr>
                    <th class="r0_c0">省/市</th>
                    <th class="r0_c1">Jan</th>
                    <th class="r0_c2">Feb</th>
                    <th class="r0_c3">Mar</th>
                    <th class="r0_c4">Apr</th>
                    <th class="r0_c5">May</th>
                    <th class="r0_c6">Jun</th>
                    <th class="r0_c7">Jul</th>
                    <th class="r0_c8">Aug</th>
                    <th class="r0_c9">Sep</th>
                    <th class="r0_c10">Oct</th>
                    <th class="r0_c11">Nov</th>
                    <th class="r0_c12">Dec</th>
                    <th class="r0_c13">总计</th>
                </tr>
            </table>
        </div>
    </div>
    <div title="各机型问题汇总" style="overflow-y: hidden;">
        <div class="pad_l_10">
            <table width="100%">
                <tr>
                    <td>
                        <label class="report_label">巡检年度</label>
                        <select id="year_2" style="width:85px;">
                            <c:forEach items="${years }" var="item">
                                <option value="${item }">${item }&nbsp;年</option>
                            </c:forEach>
                        </select>
                    </td>
                    <td>
                        <label class="report_label">机构</label>
                        <input id="departId_2" type="hidden">
                        <input id="departname_2" readonly="readonly" style="width: 250px;"/>
                        <t:choose hiddenName="departId_2" hiddenid="id" inputTextname="departname_2"
                                  textname="shortname"
                                  title="机构列表" url="zyInspectionReportController.do?goChooseOrgsForIrReport"
                                  name="orgList" width="660px" height="550px"
                                  icon="icon-search" isclear="true"></t:choose>
                    </td>
                    <td>
                        <label class="report_label">机型</label>
                        <t:comboTree url="zyInspectionReportController.do?getEsTypesTreeForIrReport" name="esTypeId"
                                     id="esTypeId" multiple="true" width="250"/>
                        <%--<input id="esTypeId" type="hidden" >
                        <input id="esTypeName" readonly="readonly" style="width: 250px;" />
                        <t:choose hiddenName="esTypeId" hiddenid="id" inputTextname="esTypeName" textname="text"
                            title="机型列表" url="zyInspectionReportController.do?goChooseEsTypeForIrReport" name="esTypeList" width="660px" height="550px"
                            icon="icon-search"  isclear="true"></t:choose>--%>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                           onclick="searchReport(2)">查询</a>
                    </td>
                </tr>
            </table>
            <div style="text-align:right; padding-right:10px;">
                <a href="javascript:void(0);" class="easyui-linkbutton"
                   data-options="iconCls:'icon-putout',plain:'true'" onclick="exportReport(2)">导出报告</a>
            </div>
            <hr/>
            <table id="pbTable" class="report_table">
                <tr>
                    <th>问题</th>
                    <th>Jan</th>
                    <th>Feb</th>
                    <th>Mar</th>
                    <th>Apr</th>
                    <th>May</th>
                    <th>Jun</th>
                    <th>Jul</th>
                    <th>Aug</th>
                    <th>Sep</th>
                    <th>Oct</th>
                    <th>Nov</th>
                    <th>Dec</th>
                    <th>总计</th>
                </tr>
                <tr>
                    <td>问题总数</td>
                    <td id="t_total_1"></td>
                    <td id="t_total_2"></td>
                    <td id="t_total_3"></td>
                    <td id="t_total_4"></td>
                    <td id="t_total_5"></td>
                    <td id="t_total_6"></td>
                    <td id="t_total_7"></td>
                    <td id="t_total_8"></td>
                    <td id="t_total_9"></td>
                    <td id="t_total_10"></td>
                    <td id="t_total_11"></td>
                    <td id="t_total_12"></td>
                    <td id="t_total_13"></td>
                </tr>
                <tr>
                    <td>问题占比</td>
                    <td id="t_pt_1"></td>
                    <td id="t_pt_2"></td>
                    <td id="t_pt_3"></td>
                    <td id="t_pt_4"></td>
                    <td id="t_pt_5"></td>
                    <td id="t_pt_6"></td>
                    <td id="t_pt_7"></td>
                    <td id="t_pt_8"></td>
                    <td id="t_pt_9"></td>
                    <td id="t_pt_10"></td>
                    <td id="t_pt_11"></td>
                    <td id="t_pt_12"></td>
                    <td id="t_pt_13"></td>
                </tr>
            </table>
            <br/>
            <div style="min-width:1400px;">
                <div id="highchartContainerOfEsPie" style="width: 49%;height:400px;display: inline-block;"></div>
                <div id="highchartContainerOfEsLine" style="width: 49%;height:400px;display: inline-block;"></div>
            </div>
        </div>
    </div>
</div>
</body>
